<?php

namespace App\Listeners;

use App\Events\OrderCompletedEvent;
use App\Models\ClickLog;
use App\Models\DistributorUser;
use App\Models\IncomeDetails;
use App\Models\StatisticDetail;
use App\Models\User;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class UpdateStatistics implements ShouldQueue
{
    /**
     * 任务被处理的延迟时间（秒）。
     *
     * @var int
     */
    public $delay = 5;

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  \App\Events\OrderCompletedEvent  $event
     * @return void|bool
     */
    public function handle(OrderCompletedEvent $event)
    {
        $orderInfo = $event->orderInfo;
        Log::info('触发Distributor监听器 -> 订单ID：' . $orderInfo->order_nu);

        ClickLog::where('user_id', $orderInfo->user_id)->where('order_nu', $orderInfo->order_nu)->update(['is_pay' => 1]);
        StatisticDetail::where('user_id', $orderInfo->user_id)->where('order_nu', $orderInfo->order_nu)->update(['is_pay' => 1]);

    }
}
